package cn.itcast.demo.controller;

import cn.itcast.demo.pojo.User;
import cn.itcast.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController //这个controller只有在纯rest情况下才能使用，原因在于如果有视图解析，ResponseBody会使得其全部失效，
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("users")//普通表单get请求
    public List<User> queryUserByIds(@RequestParam("ids")List<Long> ids){

        List<User> users = userService.queryUserByIds(ids);

        if (users != null && 0!=users.size()) {
            return users;
        }

        return null;
    }
}
